import 'package:eh_mobile/common/utils/extension.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_svg/svg.dart';
import 'package:get/get.dart';

import '../values/svg_image.dart';

class NavBarTitle extends StatelessWidget {
  Widget childWidget;
  final String name;
  final List<Widget>? actions;
  Function? backBlock;
  Color? appBarColor;
  Widget? leadingWidget;

  NavBarTitle(
      {Key? key,
      required this.childWidget,
      this.name = '',
      this.actions,
      this.backBlock,
      this.appBarColor,
      this.leadingWidget})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: appBarColor,
        leading: leadingWidget ??
            UnconstrainedBox(
              child: Container(
                width: 42.r,
                height: 32.r,
                padding: const EdgeInsets.fromLTRB(0, 4, 0, 4).r,
                decoration: BoxDecoration(
                  color: const Color.fromRGBO(222, 222, 222, 0.1),
                  borderRadius: BorderRadius.circular(16.r),
                ),
                child: SvgPicture.asset(
                  SVGImage.icReturnSvg,
                  // fit: BoxFit.contain,
                  colorFilter:
                      const ColorFilter.mode(Colors.white, BlendMode.srcIn),
                ),
              ).onClick(() {
                if (backBlock != null) {
                  backBlock!();
                } else {
                  Get.back();
                }
              }),
            ),
        actions: actions,
        title: Text(
          name,
          style: 22.ts,
        ),
      ),
      body: childWidget,
    );
  }
}
